package com.maikang.exammall.repository;

import com.maikang.exammall.entity.Hospital;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface HospitalRepository extends BaseRepository<Hospital, Long>, JpaSpecificationExecutor<Hospital> {

    @Query("UPDATE Hospital hospital SET hospital.orderCount = hospital.orderCount + 1 WHERE hospital.id IN (:ids)")
    @Modifying
    void incrementOrderCountByIds(@Param("ids") Iterable<Long> ids);

    List<Hospital> findByNameContaining(String name, Pageable topTwenty);
    List<Hospital> findByNameContainingAndCityIdEquals(String name, Long cityId, Pageable topTwenty);

    @Query("SELECT hospital.address FROM Hospital hospital WHERE hospital.id = :id")
    String findAddressById(Long id);
}
